// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    isShow:true
    
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  handleClick(){
    //点击跳转到list页面
    wx.navigateTo({
      url: '/pages/list/list',
      events: {
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        },
        someEvent: function(data) {
          console.log(data)
        }
      },
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })

  },
  onLoad() {
    this.getUserInfo();
  },
  bindGetUserInfo(data){
    console.log(data);
    //判断用户点击的是否是允许
    if(data.detail.rawData){
      this.getUserInfo();
    }
  },
  getUserInfo(e) {
    console.log(e);
    wx.getSetting({
      success: res => {
        console.log(res.authSetting['scope.userInfo']);
         if(res.authSetting['scope.userInfo']){
            wx.getUserInfo({
              success: res => {
                this.setData({
                  userInfo: res.userInfo,
                  isShow:false//授权按钮的显示
                })
                console.log(res.userInfo)
              },fail:e => {
                console.log("获取用户信息失败" + e);
              }
            })
         }
      }
    })
  }
})
